<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>EASY后台-编辑</title>
    <link rel="icon" th:href="@{/static/images/favicon.ico}">
    <link rel="stylesheet" th:href="@{/static/css/common.css}">
    <link rel="stylesheet" th:href="@{/static/layui/css/layui.css}">
</head>
<body>
<div class="easy-container">
    <form class="layui-form" id="dataForm" lay-filter="dataForm">
        <input type="text" name="<#list fieldList as field><#if field.columnPk>${field.javaField}</#if></#list>" th:field="${r'${data.'}<#list fieldList as field><#if field.columnPk>${field.javaField}</#if></#list>${r'}'}" class="layui-input" style="display: none">
<#if genPageFormType == 'ONE'>
    <#list formFieldList as field>
        <div class="layui-form-item">
            <label class="layui-form-label <#if field.pageFormRequired>required</#if>">${field.javaFieldComment}</label>
            <div class="layui-input-block">
            <#if field.pageHtmlType == 'INPUT_NUMBER'>
                <input type="number" name="${field.javaField}" th:field="${r'${data.'}${field.javaField}${r'}'}" <#if field.pageFormRequired>lay-verify="required"</#if> autocomplete="off" class="layui-input" step="1" lay-affix="number">
            <#elseif field.pageHtmlType == 'SELECT'>
                <select name="${field.javaField}" th:field="${r'${data.'}${field.javaField}${r'}'}" <#if field.pageFormRequired>lay-verify="required"</#if> th:with="dataList=${r'${@dictService.listData('}'${field.pageDictType}'${r')}'}">
                    <option th:each="dict : ${r'${dataList}'}" th:text="${r'${dict.dictItem}'}" th:value="${r'${dict.dictValue}'}"></option>
                </select>
            <#elseif field.pageHtmlType == 'CHECKBOX'>
                <input type="checkbox" name="${field.javaField}" value="true" th:field="${r'${data.'}${field.javaField}${r'}'}">
            <#elseif field.pageHtmlType == 'RADIO'>
                <#list dictTypeList as dictType>
                <#if field.pageDictType == dictType.dictCode>
                <#list dictType.dataList as dictData>
                <input type="radio" name="${field.javaField}" value="${dictData.dictValue}" title="${dictData.dictItem}" th:checked="${r'${data.'}${field.javaField}${r' == '}'${dictData.dictValue}'${r'}'}">
                </#list>
                <#else>
                <input type="radio" name="${field.javaField}" value="" title="选项1" th:checked="${r'${data.'}${field.javaField}${r' == '}''${r'}'}">
                </#if>
                </#list>
            <#elseif field.pageHtmlType == 'DATE'>
                <input type="text" name="${field.javaField}" id="${field.javaField}" th:field="${r'${data.'}${field.javaField}${r'}'}" <#if field.pageForm>lay-verify="required|date"<#else>lay-verify="date"</#if> placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
            <#elseif field.pageHtmlType == 'DATETIME'>
                <input type="text" name="${field.javaField}" id="${field.javaField}" th:field="${r'${data.'}${field.javaField}${r'}'}" <#if field.pageFormRequired>lay-verify="required"</#if> placeholder="yyyy-MM-dd HH:mm:ss" autocomplete="off" class="layui-input">
            <#elseif field.pageHtmlType == 'TIME'>
                <input type="text" name="${field.javaField}" id="${field.javaField}" th:field="${r'${data.'}${field.javaField}${r'}'}" <#if field.pageFormRequired>lay-verify="required"</#if> placeholder="HH:mm:ss" autocomplete="off" class="layui-input">
            <#elseif field.pageHtmlType == 'YEAR'>
                <input type="text" name="${field.javaField}" id="${field.javaField}" th:field="${r'${data.'}${field.javaField}${r'}'}" <#if field.pageFormRequired>lay-verify="required"</#if> placeholder="yyyy" autocomplete="off" class="layui-input">
            <#elseif field.pageHtmlType == 'SWITCH'>
                <input type="checkbox" name="${field.javaField}" lay-skin="switch" th:field="${r'${data.'}${field.javaField}${r'}'}" value="true" title="ON|OFF">
            <#elseif field.pageHtmlType == 'TEXTAREA'>
                <textarea name="${field.javaField}" th:field="${r'${data.'}${field.javaField}${r'}'}" class="layui-textarea" <#if field.pageFormRequired>lay-verify="required"</#if> placeholder="请输入"></textarea>
            <#else>
                <input type="text" name="${field.javaField}" th:field="${r'${data.'}${field.javaField}${r'}'}" <#if field.pageFormRequired>lay-verify="required"</#if> placeholder="请输入" class="layui-input">
            </#if>
            </div>
        </div>
    </#list>
<#elseif genPageFormType == 'TWO'>
<#list formFieldList as field>
    <#if (field_index % 2) == 0>
        <div class="layui-row">
    </#if>
            <div class="layui-col-sm6">
                <div class="layui-form-item">
                    <label class="layui-form-label <#if field.pageFormRequired>required</#if>">${field.javaFieldComment}</label>
                    <div class="layui-input-block">
                    <#if field.pageHtmlType == 'INPUT_NUMBER'>
                        <input type="number" name="${field.javaField}" th:field="${r'${data.'}${field.javaField}${r'}'}" <#if field.pageFormRequired>lay-verify="required"</#if> autocomplete="off" class="layui-input" step="1" lay-affix="number">
                    <#elseif field.pageHtmlType == 'SELECT'>
                        <select name="${field.javaField}" th:field="${r'${data.'}${field.javaField}${r'}'}" <#if field.pageFormRequired>lay-verify="required"</#if> th:with="dataList=${r'${@dictService.listData('}'${field.pageDictType}'${r')}'}">
                            <option th:each="dict : ${r'${dataList}'}" th:text="${r'${dict.dictItem}'}" th:value="${r'${dict.dictValue}'}"></option>
                        </select>
                    <#elseif field.pageHtmlType == 'CHECKBOX'>
                        <input type="checkbox" name="${field.javaField}" value="true" th:field="${r'${data.'}${field.javaField}${r'}'}">
                    <#elseif field.pageHtmlType == 'RADIO'>
                    <#list dictTypeList as dictType>
                    <#if field.pageDictType == dictType.dictCode>
                    <#list dictType.dataList as dictData>
                        <input type="radio" name="${field.javaField}" value="${dictData.dictValue}" title="${dictData.dictItem}" th:checked="${r'${data.'}${field.javaField}${r' == '}'${dictData.dictValue}'${r'}'}">
                    </#list>
                    <#else>
                        <input type="radio" name="${field.javaField}" value="" th:checked="${r'${data.'}${field.javaField}${r' == '}''${r'}'}">
                    </#if>
                    </#list>
                    <#elseif field.pageHtmlType == 'DATE'>
                        <input type="text" name="${field.javaField}" id="${field.javaField}" th:field="${r'${data.'}${field.javaField}${r'}'}" <#if field.pageForm>lay-verify="required|date"<#else>lay-verify="date"</#if> placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                    <#elseif field.pageHtmlType == 'DATETIME'>
                        <input type="text" name="${field.javaField}" id="${field.javaField}" th:field="${r'${data.'}${field.javaField}${r'}'}" <#if field.pageFormRequired>lay-verify="required"</#if> placeholder="yyyy-MM-dd HH:mm:ss" autocomplete="off" class="layui-input">
                    <#elseif field.pageHtmlType == 'TIME'>
                        <input type="text" name="${field.javaField}" id="${field.javaField}" th:field="${r'${data.'}${field.javaField}${r'}'}" <#if field.pageFormRequired>lay-verify="required"</#if> placeholder="HH:mm:ss" autocomplete="off" class="layui-input">
                    <#elseif field.pageHtmlType == 'YEAR'>
                        <input type="text" name="${field.javaField}" id="${field.javaField}" th:field="${r'${data.'}${field.javaField}${r'}'}" <#if field.pageFormRequired>lay-verify="required"</#if> placeholder="yyyy" autocomplete="off" class="layui-input">
                    <#elseif field.pageHtmlType == 'SWITCH'>
                        <input type="checkbox" name="${field.javaField}" lay-skin="switch" th:field="${r'${data.'}${field.javaField}${r'}'}" value="true" title="ON|OFF">
                    <#elseif field.pageHtmlType == 'TEXTAREA'>
                        <textarea name="${field.javaField}" th:field="${r'${data.'}${field.javaField}${r'}'}" class="layui-textarea" <#if field.pageFormRequired>lay-verify="required"</#if> placeholder="请输入"></textarea>
                    <#else>
                        <input type="text" name="${field.javaField}" th:field="${r'${data.'}${field.javaField}${r'}'}" <#if field.pageFormRequired>lay-verify="required"</#if> placeholder="请输入" class="layui-input">
                    </#if>
                    </div>
                </div>
            </div>
    <#if (field_index % 2) == 1 || field_index == (formFieldList?size - 1)>
        </div>
    </#if>
</#list>
<#else>
<#list formFieldList as field>
    <#if (field_index % 3) == 0>
        <div class="layui-row">
    </#if>
            <div class="layui-col-md4">
                <div class="layui-form-item">
                    <label class="layui-form-label <#if field.pageFormRequired>required</#if>">${field.javaFieldComment}</label>
                    <div class="layui-input-block">
                    <#if field.pageHtmlType == 'INPUT_NUMBER'>
                        <input type="number" name="${field.javaField}" th:field="${r'${data.'}${field.javaField}${r'}'}" <#if field.pageFormRequired>lay-verify="required"</#if> autocomplete="off" class="layui-input" step="1" lay-affix="number">
                    <#elseif field.pageHtmlType == 'SELECT'>
                        <select name="${field.javaField}" th:field="${r'${data.'}${field.javaField}${r'}'}" <#if field.pageFormRequired>lay-verify="required"</#if> th:with="dataList=${r'${@dictService.listData('}'${field.pageDictType}'${r')}'}">
                            <option th:each="dict : ${r'${dataList}'}" th:text="${r'${dict.dictItem}'}" th:value="${r'${dict.dictValue}'}"></option>
                        </select>
                    <#elseif field.pageHtmlType == 'CHECKBOX'>
                        <input type="checkbox" name="${field.javaField}" value="true" th:field="${r'${data.'}${field.javaField}${r'}'}">
                    <#elseif field.pageHtmlType == 'RADIO'>
                    <#list dictTypeList as dictType>
                    <#if field.pageDictType == dictType.dictCode>
                    <#list dictType.dataList as dictData>
                        <input type="radio" name="${field.javaField}" value="${dictData.dictValue}" title="${dictData.dictItem}" th:checked="${r'${data.'}${field.javaField}${r' == '}'${dictData.dictValue}'${r'}'}">
                    </#list>
                    <#else>
                        <input type="radio" name="${field.javaField}" value="" th:checked="${r'${data.'}${field.javaField}${r' == '}''${r'}'}">
                    </#if>
                    </#list>
                    <#elseif field.pageHtmlType == 'DATE'>
                        <input type="text" name="${field.javaField}" id="${field.javaField}" th:field="${r'${data.'}${field.javaField}${r'}'}" <#if field.pageForm>lay-verify="required|date"<#else>lay-verify="date"</#if> placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                    <#elseif field.pageHtmlType == 'DATETIME'>
                        <input type="text" name="${field.javaField}" id="${field.javaField}" th:field="${r'${data.'}${field.javaField}${r'}'}" <#if field.pageFormRequired>lay-verify="required"</#if> placeholder="yyyy-MM-dd HH:mm:ss" autocomplete="off" class="layui-input">
                    <#elseif field.pageHtmlType == 'TIME'>
                        <input type="text" name="${field.javaField}" id="${field.javaField}" th:field="${r'${data.'}${field.javaField}${r'}'}" <#if field.pageFormRequired>lay-verify="required"</#if> placeholder="HH:mm:ss" autocomplete="off" class="layui-input">
                    <#elseif field.pageHtmlType == 'YEAR'>
                        <input type="text" name="${field.javaField}" id="${field.javaField}" th:field="${r'${data.'}${field.javaField}${r'}'}" <#if field.pageFormRequired>lay-verify="required"</#if> placeholder="yyyy" autocomplete="off" class="layui-input">
                    <#elseif field.pageHtmlType == 'SWITCH'>
                        <input type="checkbox" name="${field.javaField}" lay-skin="switch" th:field="${r'${data.'}${field.javaField}${r'}'}" value="true" title="ON|OFF">
                    <#elseif field.pageHtmlType == 'TEXTAREA'>
                        <textarea name="${field.javaField}" th:field="${r'${data.'}${field.javaField}${r'}'}" class="layui-textarea" <#if field.pageFormRequired>lay-verify="required"</#if> placeholder="请输入"></textarea>
                    <#else>
                        <input type="text" name="${field.javaField}" th:field="${r'${data.'}${field.javaField}${r'}'}" <#if field.pageFormRequired>lay-verify="required"</#if> placeholder="请输入" class="layui-input">
                    </#if>
                    </div>
                </div>
            </div>
    <#if (field_index % 3) == 2 || field_index == (formFieldList?size - 1)>
        </div>
    </#if>
</#list>
</#if>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="submitForm">保存</button>
                <button type="reset" class="layui-btn layui-btn-primary" id="cancelForm">取消</button>
            </div>
        </div>
    </form>
</div>
</body>

<script th:src="@{/static/js/jquery.js}"></script>
<script th:src="@{/static/layui/layui.js}"></script>
<script type="text/javascript" th:inline="javascript">
    layui.use(['element', 'layer', 'table', 'laydate', 'form'], function () {
        var element = layui.element;
        var layer = layui.layer;
        var table = layui.table;
        var laydate = layui.laydate;
        var form = layui.form;

<#list formFieldList as field>
    <#if field.pageHtmlType == 'DATETIME'>
        laydate.render({
            elem: '#${field.javaField}',
            type: 'datetime',
            format: 'yyyy-MM-dd HH:mm:ss',
            fullPanel: true
        });
    <#elseif field.pageHtmlType == 'TIME'>
        laydate.render({
            elem: '#${field.javaField}',
            type: 'time',
            format: 'HH:mm:ss'
        });
    <#elseif field.pageHtmlType == 'YEAR'>
        laydate.render({
            elem: '#${field.javaField}',
            type: 'year',
            format: 'yyyy'
        });
    <#elseif field.pageHtmlType == 'DATE'>
        laydate.render({
            elem: '#${field.javaField}',
            type: 'date',
            format: 'yyyy-MM-dd'
        });
    </#if>
</#list>

        // 保存
        form.on('submit(submitForm)', function (form) {
            var data = form.field;
            $.ajax({
                url: '/${entityName}/edit',
                type: 'PUT',
                contentType: 'application/json',
                dataType: 'json',
                data: JSON.stringify(data),
                success: function (response) {
                    if (response.code === 200) {
                        // 关闭
                        parent.layer.close(parent.layer.getFrameIndex(window.name));
                        // 刷新
                        parent.location.reload();

                        layer.msg('编辑成功', {icon: 1});
                    } else {
                        layer.msg(response.msg, {icon: 0});
                    }
                },
                error: function (xhr, status, error) {
                    layer.msg('请求失败', {icon: 0});
                }
            });
            return false;
        });

        // 取消
        $('#cancelForm').on('click', function () {
            parent.layer.close(parent.layer.getFrameIndex(window.name));
            return false;
        });

    });
</script>
</html>